/* Copyright 2009 (c) ENSI de Bourges
 * 		88 boulevard Lahitolle, 18020 Bourges Cedex, France
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * \file application-data.h
 * \brief Header for the application's data types and functions
 * \author Steve Dodier <sidnioulz@gmail.com>
 *
 * This file contains data types describing a LiveSecurity instance.
 */
#ifndef __APPLICATION_DATA_H
#define __APPLICATION_DATA_H
#ifdef __cplusplus
extern "C" {
#endif
#include <gtk/gtk.h>
#include <glib.h>

#include "data-types.h"
#include "frame-common.h"
#include "machine.h"
#include "settings-manager.h"



/** \struct ls_instance_t
 * \brief Data structure containing all the variables needed to run LiveSecurity
 *
 * This data structure contains all the variables that can be needed in any part
 * of a LiveSecurity instance. It contains lists of available frames and
 * machines, some Gtk objects that can be needed everywhere in the source code,
 * and a mutex for non-thread-safe library calls (such as libploticus).
 */
typedef struct __ls_instance_t {
	GList			*frames_list;		/**< \brief The list of frames currently in use in the application */
	GList			*machines_list;		/**< \brief The list of available machines */
	GtkBuilder 		*builder;			/**< \brief The GtkBuilder of the application's GUI */

	GtkWidget 		*table;				/**< \brief The table in which frames are contained */
	guint			children_size[LAST_SIZE_RATIO]; /**< For each size ratio, tells the number of children of this size */
	frame_t			**slot_data;		/**< \brief Represents the slots in the table. Getters and setters can be used
											 to tell which frame is in each slot */

	char			*data_dir;			/**< \brief A folder where to look for application data files */
	char			*config_dir;		/**< \brief A folder where to look for user configuration */
	char			*machines_dir;		/**< \brief A folder where to look for machines */

	settings_t		*settings;			/**< \brief A struct containing application settings */
} ls_instance_t;



/** \fn int frame_list_add (GList **, frame_t *)
 * \brief Adds a frame to the frames list
 *
 * This function adds a frame to a frames list, and puts it in the table linked
 * to this list.
 * @param[out] list the address of the pointer to the list (because it may be modified)
 * @param[in] newelem a pointer to the new frame
 * @return 0 if adding the frame to the list and table was successful, another value on error
 */
int frame_list_add (GList **, frame_t *);



/** \fn int frame_list_remove (GList **, frame_t *)
 * \brief Removes a frame from the frames list
 *
 * This function removes a frame from the table linked to the list given in parameter,
 * frees it and removes it from the list.
 * @param[out] list the address of the pointer to the list (because it may be modified)
 * @param[in] elem a pointer to the frame
 * @return 0 if removing the frame from the list and table was successful, another value on error
 */
int frame_list_remove (GList **, frame_t *);



/** \fn void frame_list_free (GList *)
 * \brief Frees a list of frames and it's content
 *
 * This function frees all the frames in a list and frees the list too.
 * @param[out] list the pointer to the list
 */
void frame_list_free (GList *);



/** \fn ls_instance_t *livesecurity_instance ()
 * \brief Returns a pointer to the current LiveSecurity instance
 *
 * This function returns a pointer to the current instance of LiveSecurity (it
 * is implemented as a ls_instance_t static struct). If the instance
 * doesn't exist, it is created beforehand.
 * @return the current LiveSecurity instance, properly initialised
 */
ls_instance_t* livesecurity_instance ();



/** \fn void livesecurity_instance_free()
 * \brief Frees the current LiveSecurity instance
 *
 * \warning This function should not be called when the Gtk loop is running.
 *
 * This function frees the whole current LiveSecurity instance, by freeing all
 * of its members before freeing the ls_instance_t struct itself.
 */
void livesecurity_instance_free ();
#ifdef __cplusplus
}
#endif
#endif
